package com.coocaa.ops.plus.dashboard.v1.auth;

import com.coocaa.ops.common.core.base.model.R;
import com.coocaa.ops.plus.dashboard.v1.auth.model.MyAccountModel;
import com.coocaa.ops.plus.dashboard.v1.auth.model.PlusConfigInfo;
import com.coocaa.ops.plus.dashboard.v1.auth.service.impl.PlusLoginServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author bijiahao
 * @date : 2019/6/24.
 * @description 扩展模块的 登录验证控制器
 *
 */
@RestController
@RequestMapping("/myExtend")
public class PlusLoginController {

    @Autowired
    private PlusLoginServiceImpl plusLoginService;

    @RequestMapping("/getPlusConfigInfo")
    public R getPlusConfigInfo(HttpServletRequest request) {
        PlusConfigInfo plusConfigInfo = plusLoginService.getPlusConfigInfo(request);
        return R.ok().data(plusConfigInfo);
    }


    @RequestMapping("/login")
    public R login(HttpServletRequest request) {
        String username = request.getParameter("username");
        if (StringUtils.isBlank(username)) {
            return R.fail("用户名不能为空！");
        }
        String password = request.getParameter("password");
        MyAccountModel accountModel = new MyAccountModel(username, password);
        return plusLoginService.login(accountModel, request);
    }
}
